package com.store.app.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.store.app.R;
import com.store.app.bean.StoreDetailServiceBean;

import java.util.List;

/**
 * Created by liuwy on 2016/2/19.
 */
public class ServiceAdapter extends RecyclerView.Adapter<ServiceAdapter.ViewHolder> {


    private List<StoreDetailServiceBean> serviceList;

    private Context context;

    private LayoutInflater mInflater;

    public ServiceAdapter(List<StoreDetailServiceBean> serviceList, Context context) {
        this.serviceList = serviceList;
        this.context = context;
        mInflater = LayoutInflater.from(context);
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.services_gallery_item,
                parent, false);
        ViewHolder viewHolder = null;
        viewHolder = new ViewHolder(view);

        viewHolder.ivService = (ImageView) view.findViewById(R.id.iv_services);
        viewHolder.tvName = (TextView) view.findViewById(R.id.tv_services);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        StoreDetailServiceBean serviceBean = serviceList.get(position);
        holder.ivService.setBackgroundResource(serviceBean.getResId());
        holder.tvName.setText(serviceBean.getName());
    }


    @Override
    public int getItemCount() {
        return serviceList == null ? 0 : serviceList.size();
    }

//    @Override
//    public Object getItem(int position) {
//        return serviceList.get(position);
//    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public ViewHolder(View arg0) {
            super(arg0);
        }

        ImageView ivService;
        TextView tvName;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

//    @Override
//    public int getItemCount() {
//        return 0;
//    }

//    @Override
//    public View getView(int position, View convertView, ViewGroup parent) {
//
//        ViewHolder viewHolder ;
//        if (convertView == null) {
//            viewHolder = new ViewHolder();
//
//
//            convertView = LayoutInflater.from(context).inflate(R.layout.services_gallery_item, null);
//
//            viewHolder.ivService = (ImageView) convertView.findViewById(R.id.iv_services);
//            viewHolder.tvName = (TextView) convertView.findViewById(R.id.tv_services);
//            convertView.setTag(viewHolder);
//        } else {
//            viewHolder = (ViewHolder) convertView.getTag();
//        }
//
//
//        ServiceBean serviceBean = serviceList.get(position);
//        viewHolder.ivService.setBackgroundResource(serviceBean.getResId());
//        viewHolder.tvName.setText(serviceBean.getName());
//
//        return convertView;
//    }


//    class ViewHolder {
//        ImageView ivService;
//        TextView tvName;
//    }
}
